package com.zgkxzx.myfix;

import android.content.Context;
import android.util.Log;

import java.io.File;
import java.util.List;

/**
 * 创建者 zgkxzx
 * 日期   1/30/18
 * 描述
 */

public class PatchManger {
    private final static String TAG = PatchManger.class.getSimpleName();

    private Context context;

    private AndFixManager andFixManager;

    private File srcFile;


    public PatchManger(Context context) {
        this.context = context;
    }


    public void init(int appVersion) {
        andFixManager = new AndFixManager(context, appVersion);
        Log.d(TAG,"init "+appVersion);
    }


    public void loadPatch(String src) {
        Log.d(TAG,"loadPatch "+src);
        srcFile = new File(src);
        Patch patch = new Patch(src, context);
        loadPatch(patch);
    }

    private void loadPatch(Patch patch) {
        ClassLoader classLoader = context.getClassLoader();

        List<String> classes = null;
        Log.d(TAG,"loadPatch -- "+patch.getPatchNames());
        for (String name : patch.getPatchNames()) {
            classes = patch.getClasses(name);
            andFixManager.fix(srcFile, classLoader, classes);
        }

    }
}
